package org.example.controller;

import org.example.service.UserService;
import org.example.vo.Users;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/user_list.action")
public class UserListController extends HttpServlet {

    protected  void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

//        System.out.println("==== 测试请求是否进入Servlet ====");
        request.setCharacterEncoding("UTF-8");
        String username = request.getParameter("username");
//        String password = request.getParameter("password");
        UserService service = UserService.getInstance();
        List<Users> userList = service.queryUserList(username);
        request.setAttribute("userList", userList);
        request.setAttribute("username", username);
        request.getRequestDispatcher("./user_list.jsp").forward(request, response);

        
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
